package com.vision.util.http.down.thread;

import com.vision.util.http.down.AbsDownEntity;

import java.util.List;
import java.util.concurrent.Future;

/**
 * 处理下载完成的返回数据
 *
 * @author zhongchao
 * @date 2017-08-17
 * @since v1.0.0
 */
public abstract class DealDownedThread<T extends AbsDownEntity> extends Thread {

    private List<Future<T>> futureList;

    public DealDownedThread(DownVideoExecutorPool<T> pool) {
        this.futureList = pool.getFutureList();
    }

    @Override
    public void run() {
        try {
            while (true) {
                this.dealDowned();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 处理
     */
    abstract void dealDowned();

//    public void test() throws ExecutionException, InterruptedException {
//        Iterator<Future<T>> iterator = futureList.iterator();
//        while (iterator.hasNext()) {
//            Future<T> next = iterator.next();
//            if (next.isDone()) {
//                T t = next.get();
//                System.out.println(t.getTitle());
//                iterator.remove();
//            }
//        }
//    }
}
